﻿@page "/pages/authentication/RegisterConfirmation"
@using CleanArchitecture.Blazor.Domain.Identity


@inject UserManager<ApplicationUser> UserManager
@inject IdentityRedirectManager RedirectManager
@inject IStringLocalizer<RegisterConfirmation> L
<PageTitle>@L["Register confirmation"]</PageTitle>

<h1>@L["Register confirmation"]</h1>

<StatusMessage Message="@statusMessage" Error="true"/>

@if (EmailConfirmationLink is not null)
{
    <p>
        L["This app does not currently have a real email sender registered, see"] <a href="https://aka.ms/aspaccountconf">@L["these docs"]</a> @L["how to configure a real email sender. Normally this would be emailed:"] <a class="mud-button-root mud-button mud-button-text mud-button-text-default mud-button-text-size-medium mud-ripple" href="@EmailConfirmationLink">@L["here to confirm your account"]</a>
    </p>
}
else
{
    <MudText Typo="Typo.body1">@L["Please check your email to confirm your account."]</MudText>
}

@code {
    public const string PageUrl = "/pages/authentication/RegisterConfirmation";
    [SupplyParameterFromQuery] private string? EmailConfirmationLink { get; set; }
    private string? statusMessage;

    [CascadingParameter] private HttpContext HttpContext { get; set; } = default!;

    [SupplyParameterFromQuery] private string? Email { get; set; }

    [SupplyParameterFromQuery] private string? ReturnUrl { get; set; }

    protected override async Task OnInitializedAsync()
    {
        if (Email is null)
        {
            RedirectManager.RedirectTo("/");
        }

        var user = await UserManager.FindByEmailAsync(Email);
        if (user is null)
        {
            HttpContext.Response.StatusCode = StatusCodes.Status404NotFound;
            statusMessage = L["Error finding user for unspecified email"];
        }
    }

}